function [besttau,bestlambda]=CHlogit(tau,lambda,Row,Column,y,id)

levR{1}=1/3*ones(1,3);
levC{1}=1/3*ones(1,3);

n=length(Row);
r=length(tau);
s=length(lambda);
all=cell(r,s);
for q=1:r
    for u=1:s
        t=tau(q);
        l=lambda(u);
        for g=1:n
            ExpPayoffR=levR{1}*Row{g}';
            levR{2}=zeros(1,3);
            for j=1:3
                levR{2}(j)=exp(l*ExpPayoffR(j))/(exp(l*ExpPayoffR(1))+exp(l*ExpPayoffR(2))+exp(l*ExpPayoffR(3)));
            end
            ExpPayoffC=levC{1}*Column{g};
            levC{2}=zeros(1,3);
            for j=1:3
                levC{2}(j)=exp(l*ExpPayoffC(j))/(exp(l*ExpPayoffC(1))+exp(l*ExpPayoffC(2))+exp(l*ExpPayoffC(3)));
            end
            
            for k=2:7
                w=poisspdf(0:k-1,t)/sum(poisspdf(0:k-1,t));
                
                mixR=w(1).*levC{1};
                for j=2:k
                    mixR=mixR+w(j)*levC{j};
                end
                
                ExpPayoffR=mixR*Row{g}';
                levR{k+1}=zeros(1,3);
                for j=1:3
                    levR{k+1}(j)=exp(l*ExpPayoffR(j))/(exp(l*ExpPayoffR(1))+exp(l*ExpPayoffR(2))+exp(l*ExpPayoffR(3)));
                end
                
                mixC=w(1).*levR{1};
                for j=2:k
                    mixC=mixC+w(j)*levR{j};
                end
                
                ExpPayoffC=mixC*Column{g};
                levC{k+1}=zeros(1,3);
                for j=1:3
                    levC{k+1}(j)=exp(l*ExpPayoffC(j))/(exp(l*ExpPayoffC(1))+exp(l*ExpPayoffC(2))+exp(l*ExpPayoffC(3)));
                end
            end
            all{q,u}(g,:)=poisspdf(0,t)*levR{1};
            for k=1:7
                all{q,u}(g,:)=all{q,u}(g,:)+poisspdf(k,t)*levR{k+1};
            end
        end
    end
end

m=length(y);
Err=zeros(r,s);
for q=1:r
    for u=1:s
        err=zeros(m,1);
        for i=1:m
            err(i)=-log(all{q,u}(id(i),str2double(y(i))));
        end
        Err(q,u)=mean(err);
    end
end

[besttau,bestlambda]=find(Err==min(min(Err)));